/* Copyright 2007 Ryan Phillips.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef XBLF_H_
#define XBLF_H_

/**
 * @file xblf.h
 * @brief main header file
 */

#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <time.h>
#include "xblf_version.h"

typedef enum {
    XBLF_ERROR_SUCCESS = 0,    /**< Success */
    XBLF_ERROR_NOTQUERIED, /**< Initialized to this */
    XBLF_ERROR_PARSE,      /**< Parse Error */
    XBLF_ERROR_NET,        /**< Network Error */
    XBLF_ERROR_MEMORY      /**< Memory Error */
} xblf_error_t;

typedef enum {
    XBLF_ACCOUNT_UNKNOWN,
    XBLF_ACCOUNT_SILVER,
    XBLF_ACCOUNT_GOLD
} xblf_account_status;

typedef struct {
    const char *debug_filename;  /**< Use this filename to load the parser */
    char *gamertag;        /**< GamerTag */
    char *uri;             /**< URI to query */
    int total_bytes;       /**< Total bytes read over the network */
    xblf_error_t failed;   /**< Error Condition */
    xmlParserCtxtPtr xc;   /**< XML Parser Context */
} xblf_friend_t;

typedef struct {
    char *name;
    int total_achievements;
    int total_gamescore;
    char *image_32url;
    char *image_64url;
} xblf_usergameinfo_game_t;

typedef struct {
    xblf_usergameinfo_game_t game;
    char *last_played;
    char *details_url;
    int   achievements;
    int   gamerscore;
} xblf_recentgames_t;

/** 
 * @defgroup xblf libxblf
 * @{
 */

/** 
 * @defgroup xblf_core core api
 * @{
 */

/** 
 * @brief Initialize the library
 */
void xblf_init();

/** 
 * @brief Cleanup the library
 *
 */
void xblf_finish();

/** 
 * @brief Create a new friend
 */
xblf_friend_t* 
xblf_friend_new();

/** 
 * @brief create a new friend from a gamertag (handle)
 * @param gamertag player's handle
 */
xblf_friend_t* 
xblf_friend_new_by_tag(const char *gamertag);

/**
 * @brief deallocate a friend
 */
void 
xblf_friend_free(xblf_friend_t *f);

/**
 * @brief set the gamertag
 */
void 
xblf_friend_set_gamertag(xblf_friend_t *f, const char *gamertag);

/**
 * @brief perform the query
 * @return XBLF_ERROR_SUCCESS on success
 */
xblf_error_t
xblf_friend_query(xblf_friend_t *f);

/** @} */

/** 
 * @defgroup xblf_data data api
 * @{
 */

/**
 * @brief return account status
 */
xblf_account_status 
xblf_friend_get_account_status(xblf_friend_t *f);

int 
xblf_friend_get_gamerscore(xblf_friend_t *f);

char*
xblf_friend_get_profileurl(xblf_friend_t *f);

char*
xblf_friend_get_tileurl(xblf_friend_t *f);

char*
xblf_friend_get_reputationurl(xblf_friend_t *f);

int
xblf_friend_presence_get_online(xblf_friend_t *f);

char*
xblf_friend_presence_get_info1(xblf_friend_t *f);

char*
xblf_friend_presence_get_info2(xblf_friend_t *f);

int
xblf_friend_presence_get_valid(xblf_friend_t *f);

char*
xblf_friend_presence_get_status_text(xblf_friend_t *f);

char*
xblf_friend_presence_get_title(xblf_friend_t *f);

char*
xblf_friend_presence_lastseen(xblf_friend_t *f);

/**
 * @brief return the recent games as a link list
 */
xblf_recentgames_t**
xblf_friend_get_recentgames(xblf_friend_t *f);

/**
 * @brief free the recent games linked list
 */
void
xblf_friend_recentgames_free(xblf_recentgames_t **recent_games);

/** @} */
/** @} */

#endif

